using System.Collections.Generic;
using BCW;
using UnityEngine;

public class BankPromoUI : MonoBehaviour
{
	[SerializeField]
	private GameObject promoHolder;

	[SerializeField]
	private UILabel promoName;

	[SerializeField]
	private UILabel leftPacks;

	[SerializeField]
	private List<UIBasicSprite> carTextures;

	[SerializeField]
	private List<UIBasicSprite> gunTextures;

	[SerializeField]
	private BankAdditionalMoney additionalMoney;

	private InAppProduct _inAppProduct;

	public GameObject productPowerInfo;

	public UILabel productPowerCount;

	public InAppProduct inAppProduct
	{
		get
		{
			if (_inAppProduct == null)
			{
				_inAppProduct = GetComponentInParent<InAppProduct>();
			}
			return _inAppProduct;
		}
	}

	public void SetPromoUI()
	{
		promoHolder.SetActive(false);
		inAppProduct.lbGiveCoins.color = Color.yellow;
		inAppProduct.SetlbGiveCoins(0);
		inAppProduct.setRuleIdPlatform();
		InAppPromoController.InAppPromo promoById = InAppPromoController.instance.inAppPromos.GetPromoById(inAppProduct.idItems);
		if (inAppProduct == null || promoById == null || !promoById.Enabled)
		{
			return;
		}
		inAppProduct.lbGiveCoins.color = Color.white;
		promoHolder.SetActive(true);
		promoName.text = promoById.GetTitle();
		leftPacks.text = promoById.GetPacksLeftTitle();
		additionalMoney.gameObject.SetActive(false);
		carTextures[0].transform.parent.gameObject.SetActive(false);
		gunTextures[0].transform.parent.gameObject.SetActive(false);
		if (!promoById.promoBonuses.GiveAlternativeBonuses())
		{
			List<UIBasicSprite> list = null;
			switch (promoById.bonusImageType)
			{
			case InAppPromoController.BonusImageType.Money:
				additionalMoney.gameObject.SetActive(true);
				break;
			case InAppPromoController.BonusImageType.Vehicle:
				carTextures[0].transform.parent.gameObject.SetActive(true);
				list = carTextures;
				break;
			case InAppPromoController.BonusImageType.Weapon:
				gunTextures[0].transform.parent.gameObject.SetActive(true);
				list = gunTextures;
				break;
			}
			additionalMoney.SetAdditionalMoney((!promoById.isCashPromo) ? promoById.promoBonuses.cashAmount : promoById.promoBonuses.goldAmount, promoById.isCashPromo);
			List<string> promoMarketBonusesIds = promoById.promoBonuses.GetPromoMarketBonusesIds();
			SetProductPower(promoMarketBonusesIds);
			if (list == null)
			{
				return;
			}
			foreach (UIBasicSprite item in list)
			{
				item.transform.localScale = Vector3.one;
				item.mainTexture = null;
			}
			if (promoMarketBonusesIds.Count > 1)
			{
				for (int i = 0; i < promoMarketBonusesIds.Count; i++)
				{
					list[i] = list[i].ReplaceForCurrentPlatform();
					list[i].LoadTextureAndAlphaMask(settings.shopTextureFolderPath, MarketController.Instance.GetProduct(promoById.promoBonuses.GetPromoMarketBonusesIds()[i]).texture);
				}
			}
			else
			{
				list[1].transform.localScale = Vector3.one * 1.5f;
				list[1] = list[1].ReplaceForCurrentPlatform();
				list[1].LoadTextureAndAlphaMask(settings.shopTextureFolderPath, MarketController.Instance.GetProduct(promoById.promoBonuses.GetPromoMarketBonusesIds()[0]).texture);
			}
		}
		else
		{
			SetProductPower(null);
			additionalMoney.gameObject.SetActive(true);
			additionalMoney.SetAdditionalMoneyAlternative(promoById.promoBonuses.сashAmountAlternative, promoById.promoBonuses.goldAmountAlternative, inAppProduct);
		}
	}

	public void SetProductPower(List<string> productRewardIDs)
	{
		float num = 0f;
		if (productRewardIDs != null)
		{
			foreach (string productRewardID in productRewardIDs)
			{
				Product product = MarketController.Instance.GetProduct(productRewardID);
				if (product != null)
				{
					if (product is ProductWeapon)
					{
						num = (product as ProductWeapon).damage;
						break;
					}
					if (product is ProductTank)
					{
						num = (product as ProductTank).damage;
						break;
					}
					if (product is ProductTitan)
					{
						num = (product as ProductTitan).mainWeaponDamage;
						break;
					}
				}
			}
		}
		if (num > 0f)
		{
			productPowerCount.text = ((int)num).ToString();
			productPowerInfo.SetActive(true);
		}
		else
		{
			productPowerInfo.SetActive(false);
		}
	}

	private void OnEnable()
	{
		SetPromoUI();
		InAppPromoController.promosParsedFromJson += SetPromoUI;
	}

	private void OnDisable()
	{
		InAppPromoController.promosParsedFromJson -= SetPromoUI;
	}
}
